const net = require('net')
const eventEmit = require("./utils/MyEventEmit");

console.log('mock执行');
const server = net.createServer(socket => {
    let i = 0;
    const handler = setInterval(() => {
        i++;
        const time = i * 20;
        const data = (100 * ( Math.sin(2 * 3.14 / 6000 * time) )).toFixed(0);
        const paddingStartData = data.padStart(4,'0');
        if (socket){
            socket.write(paddingStartData);
        }
    },20);
    socket.on('connect', () => {
        console.log('client connect to mock socket server')
        handler()
    })
    socket.on('close',() => {
        clearInterval(handler)
        console.log('mock socket server closed')
    })
    socket.on('error',() => {
        console.log('mock socket server error')
    })
}).listen(8088)

server.on('listening',function () {
    console.log('listening')
})
